<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>权限分配管理</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        h1 {
            color: #333;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 10px;
            border: 1px solid #ddd;
            text-align: left;
        }
        th {
            background-color: #f4f4f4;
        }
        .btn {
            padding: 5px 10px;
            background-color: #28a745;
            color: white;
            border: none;
            cursor: pointer;
        }
        .btn:hover {
            background-color: #218838;
        }
    </style>
</head>
<body>
<h1>权限分配管理</h1>
<form action="${pageContext.request.contextPath}/acl_roleDel" method="post">
    <table>
        <thead>
        <tr>
            <th>角色名称</th>
            <th>权限列表</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
            <tr>
                 <%--查询的用户名--%>
                <td>${acl.username}</td>
                <td>
                    <%--查询所有权限--%>
                    <c:forEach var="permission" items="${acl_roles}">
                            <label>
                                <%--权限ID--%>
                                <input class = "cl" type="checkbox" name="role_id" value="${permission.role_id}"
                               <c:if test="${permission.is_deleted==1}">
                                        checked
                                </c:if>>
                                    ${permission.role_name}
                            </label><br>
                    </c:forEach>
                </td>
                <td>                                                       <%--用户ID--%>
                    <button onclick="ti()" type="submit" class="btn" name="roleId" value="${acl.user_id}">保存</button>
                </td>
            </tr>
        </tbody>
    </table>
</form>
</body>
</html>
<script>
    function ti() {
        var roleId = document.getElementsByName("roleId")[0].value;
        var role_id = document.getElementsByName("role_id");
        var role_ids = [];
        for (var i = 0; i < role_id.length; i++) {
            if (role_id[i].checked) {
                role_ids.push(role_id[i].value);
            }
        }
        if (role_ids.length != 0 && roleId) {
            var url = "${pageContext.request.contextPath}/acl_roleDel?role_id=" + roleId + "&role_ids=" + role_ids.join(",");
            location.href = url;
        } else {
            alert("请选择角色和权限");
        }
    }
</script>
